<template>
  <el-dialog :visible.sync="dialogVisible" width="530px" :close-on-click-modal="false" :close-on-press-escape	='false'
             title="选择联系人" center>
    <div class="company-concat">
      <el-table
        ref="multipleTable"
        :data="list" max-height="300"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column prop="linker"
          label="联系人">
        </el-table-column>
        <el-table-column
          prop="title"
          label="客户名称">
        </el-table-column>
      </el-table>
    </div>
    <p class="result">已选择：{{multipleSelection.length}}个 <span>(最多选择30个联系人)</span></p>
    <div slot="footer" class="dialog-footer" align="right">
      <el-button @click="dialogVisible = false" size="mini">取 消</el-button>
      <el-button type="primary" size="mini" @click="submit" :disabled="multipleSelection.length==0">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
    export default {
        name: "dialogLinker",
        data(){
            return{
                dialogVisible:false,
                list:[],
                multipleSelection:[]
            }
        },
        methods:{
            init(selectList){
                this.list=[];
                let frag='';
                selectList.map(item=>{
                    let customer=item.custLinkVos;
                    if(customer.length>1){//超过两个
                        frag=customer.length
                    }
                    customer.map(items=>{
                        this.list.push({
                            title:item.fullname,
                            linker:items.linker,
                            email:items.email
                        })
                    })
                })
                if(this.list.length==1||frag==''){//单个自动跳转
                    this.multipleSelection=this.list;
                    this.submit();
                }else{
                    this.dialogVisible=true;
                }
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            submit(){
                let str = '', arr = [];
                const list = this.multipleSelection;
                if (list.length==0&&list.length>30) return;
                list.forEach(item => {
                    arr.push(item.email)
                });
                str = arr.join(',')
                this.$router.push({
                    path: '/mail/write/index',
                    query: {
                        customer: str
                    }
                })
            }
        }
    }
</script>

<style scoped lang="scss">
  .result{
    font-size: 12px;
    margin-top: 10px !important;
    color: #232323;
    span{
      color: red;
    }
  }
</style>
